﻿#pragma once

#include <learn/ais/ais_camera.h>
#include <learn/mesh/mesh.h>
#include <learn/painter/buffer.h>
#include <learn/painter/painter2d.h>

namespace xi
{

namespace painter
{

using namespace xi::ais;
using namespace xi::mesh;

class EXT_SYMBOL Painter3D
{
  public:
    /**
     * @brief 构造函数
     *
     * @param[in] width
     * @param[in] height
     */
    Painter3D(int width, int height);

    /**
     * @brief 刷新窗口
     *
     */
    void refresh();

    /**
     * @brief 修改画框大小
     *
     * @param[in] width
     * @param[in] height
     */
    void resize(int width, int height);

    /**
     * @brief 获得图像
     *
     * @return TGA_Image
     */
    TGA_Image frame();

    /**
     * @brief 设置图像
     *
     * @param[in] frame
     */
    void set_frame(TGA_Image frame);

    /**
     * @brief 填充 3D 三角形
     *
     * @param[in] xyz
     * @param[in] uv
     * @param[in] texture
     */
    void fill_triangle(const Vec3f *xyz, const Vec2f *uv, const TGA_Image &texture);

    /**
     * @brief 绘制模型
     *
     * @param[in] mesh
     * @param[in] texture
     * @param[in] camera
     */
    void draw_object(const Mesh_Data &mesh, const TGA_Image &texture, std::shared_ptr<Camera> camera);

  protected:
    Painter2D m_painter2D;
    Buffer<float> m_zBuffer;
};

} // namespace painter

} // namespace xi
